const { app } = require('./express');
const { querySql } = require('./mysql')

const resultData = {
    code: '',
    msg: '',
    data: ''
}
app.get('/test', (req, res) => {
    res.send("hello")
})
app.post('/api/book/query', (req, res) => {
    let sql = `select * FROM b_books`;
    let sqlParam = [];
    querySql(sql, sqlParam, (err, result) => {
        const baseReturn = returnData('2000', '查询成功', result);
        res.send(baseReturn)
    })
})
app.post('/api/user/login', (req, res) => {
    console.log(req.body);
    const data = { token: 'djndjendjendjwndjwnd2324324dnejdnj212' }
    const baseReturn = returnData('2000', '查询成功', data);
    res.send(baseReturn)
})
app.get('/api/user/info', (req, res) => {
    console.log(req.params);
    console.log(req.query);
    const user = { name: 'zhangsan', avatar: 'https://s1.ax1x.com/2022/07/25/jx9ehV.png' }
    const baseReturn = returnData('2000', '查询成功', user);
    res.send(baseReturn)
})

function returnData(code, msg, data) {
    resultData.code = code;
    resultData.msg = msg;
    resultData.data = data
    return resultData;
}